package com.peng.leetcode.tree;

/**
 * PruneTree2
 * 814. 二叉树剪枝
 * https://leetcode.cn/problems/binary-tree-pruning/
 *
 * @author: lupeng6
 * @create: 2023/2/4 12:55
 */
public class PruneTree2 {
    public TreeNode pruneTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        root.left = pruneTree(root.left);
        root.right = pruneTree(root.right);
        if (root.left == null && root.right == null && root.val == 0) {
            return null;
        }
        return root;
    }
}
